package com.web.expspringboot.controller;

import com.web.expspringboot.entity.CartSt;
import com.web.expspringboot.entity.ProductSt;
import com.web.expspringboot.service.CartService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    CartService cartService;

    @PostMapping("/addCart")
    public boolean addProduct(long productId) {
        return cartService.addCart(productId);
    }

    @PostMapping("/deleteCart")
    public boolean deleteProduct(long productId) {
        return cartService.deleteCart(productId);
    }

    @PostMapping("/getCart")
    public List<CartSt> getCart() {
        return cartService.getCart();
    }

    @GetMapping("/getCartProducts")
    public List<ProductSt> getCartProducts(){
        return cartService.getCartProducts();
    }

    @PostMapping("/purchaseProduct")
    public int purchaseProduct(@Param("productId") long productId) {
        return cartService.purchaseProduct(productId);
    }
}
